package com.ilibrary.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.ilibrary.db.dao.hibernate.NewsCategoryDao;
import com.ilibrary.db.entity.NewsCategory;
import com.ilibrary.service.NewsCategoryService;
import com.ilibrary.web.dto.ResultDto;
import com.ilibrary.web.vo.NewsCategoryVO;

public class NewsCategoryServiceImpl implements NewsCategoryService {
	
	private NewsCategoryDao newsCategoryDao;
	
	public NewsCategoryDao getNewsCategoryDao() {
		return newsCategoryDao;
	}
	public void setNewsCategoryDao(NewsCategoryDao newsCategoryDao) {
		this.newsCategoryDao = newsCategoryDao;
	}
	
	@Override
	public ResultDto<NewsCategoryVO> findAll() {
		ResultDto<NewsCategoryVO> resultDto = new ResultDto<NewsCategoryVO>();
		List<NewsCategory> newsCategorieList = newsCategoryDao.findAll();
		NewsCategoryVO newsCategoryVO = null;
		for (NewsCategory newsCategory : newsCategorieList) {
			newsCategoryVO = new NewsCategoryVO();
			try {
				BeanUtils.copyProperties(newsCategoryVO, newsCategory);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			resultDto.addToResultList(newsCategoryVO);
		}
		return resultDto;
	}
	
}
